<?php

namespace app\common\model;

use app\helpers\Common;
use app\libs\traits\BaseModelTrait;

class AdminLog extends Base
{
    /**
     * Base Model Trait
     */
    use BaseModelTrait;

    protected $deleteTime = 'deleted_at';

    // 软删除字段默认值
    protected $defaultSoftDelete = 0;

    // 当前模型名称 不带前缀
    protected $name = 'admin_logs';

    public $pk = 'id';


    /**
     * Set sorting attribute
     *
     * @param $value
     * @return int
     */
    public function setSortingAttr($value)
    {
        return !empty($value) ? $value : 0;
    }

    /**
     * 虚拟字段
     *
     * 调用方式 $item->_admin_id()
     * @return mixed
     */
    public function _admin_id()
    {
        $result = $this->belongsTo('Admin', 'admin_id', 'id')->getResults();

        return $result->username;
    }
}